package com.yc.tomcat.impl;

import com.yc.tomcat.Cookie;
import com.yc.tomcat.HttpServletRequest;
import com.yc.tomcat.HttpServletResponse;
import com.yc.tomcat.ServletException;

import java.io.IOException;

public class AddCookieServlet extends HttpServletImpl{
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String name=request.getParameter("name");
        String value = request.getParameter("value");
        String age = request.getParameter("age");

 //建立cookie对象
        Cookie cookie=new CookieImpl(name,value);

        if(age!=null){
            cookie.setMaxAge(Integer.parseInt(age));
        }

        response.addCookie(cookie);

        response.sendRedirect("/cookie.s");
    }
}

